import { service } from './index';

// 任务接口
export function listTask(params) {
    return service.get('/agv/task/list', { params });
}

export function getTask(id) {
    return service.get(`/agv/task/${id}`);
}

export function addTask(data) {
    return service.post('/agv/task', data);
}

export function updateTask(data) {
    return service.put('/agv/task', data);
}

export function delTask(id) {
    return service.delete(`/agv/task/${id}`);
}

export function startTask(id) {
    return service.post(`/agv/task/start/${id}`);
}

export function endTask({ id, isAbort }) {
    return service.post(`/agv/task/end/${id}?isAbort=${isAbort}`);
}

export function preUploadTask(id) {
    return service.get(`/agv/task/preupload/${id}`);
}

export function uploadTask(id) {
    return service.post(`/agv/task/upload/${id}`);
}

// 根据时间获取任务数据
export function getTasksByTime(startTime, endTime) {
    const params = {};
    if (startTime) params.startTime = startTime;
    if (endTime) params.endTime = endTime;

    if(!startTime || !endTime){
        return service.get('/agv/task/list');
    }
    
    return service.get('/agv/task/time', {
        params 
    });
}

// 获取用户信息
export function getUserInfo(name) {
    return service.get(`/agv/user?name=${name}`);
}